<template>
  <div>
    <el-button type="primary" icon="el-icon-plus" class="mr-b15" @click="dialogVisible=true">添加分类</el-button>
    <el-table :data="NoteState.noteOptions" border>
      <el-table-column label="id" prop="id" width="100px" align="center"> </el-table-column>
      <el-table-column label="名称" prop="name" align="center"> </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="primary" icon="el-icon-edit" @click="edit(scope.row.id)">修改</el-button>
          <el-button type="danger" icon="el-icon-delete" @click="delOneClassify(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog title="添加笔记分类标题" :visible.sync="dialogVisible" width="500px" @close="closeDialog">
      <div class="flex-lrb flex-nr-c note-doalog">
        <span>笔记分类标题</span>
        <el-input v-model="noteName" placeholder="请输入内容"></el-input>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="addNote">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import { addNoteClassify } from '../api/module/note'
export default {
  //import引入的组件
  components: {},
  //子组件引用父组件:data=data 方法@search=search使用this.emit('search', '参数');
  props: [],
  data () {
    return {
      dialogVisible: true,
      noteName: ''
    };
  },
  computed: {
    ...mapState('Note', { //使用如下 {{ ClassifyState.name }}  console.log(this.ClassifyState.name)
      NoteState: state => state
    }),
  },
  methods: {
    /**关闭回调 */
    closeDialog () {
      this.noteName = '';
      this.NoteState.edit_id = '';
    },
    /**添加分类 */
    addNote () {
      let data = {
        noteName: this.noteName,
        edit_id: this.NoteState.edit_id
      }
      addNoteClassify(data).then((result) => {
        console.log(result)
      })
    }
  },
  mounted () { },
};
</script>

<style>
.note-doalog span {
  width: 120px;
}
</style>